package org.midy.infrastructure.tools;

import java.nio.channels.SelectionKey;

public class SelectorTools {
    public static String READ  = "read ";
    public static String WRITE  = "write ";

    public static String CONNECT  = "connect ";
    public static String ACCEPT  = "accept ";

    public static String parse(int status) {
        String desc = "";

        if((status & SelectionKey.OP_WRITE) == SelectionKey.OP_WRITE) {
            desc += WRITE;
        }

        if((status & SelectionKey.OP_READ) == SelectionKey.OP_READ) {
            desc += READ;
        }

        if((status & SelectionKey.OP_CONNECT) == SelectionKey.OP_CONNECT) {
            desc += CONNECT;
        }

        if((status & SelectionKey.OP_ACCEPT) == SelectionKey.OP_ACCEPT) {
            desc += ACCEPT;
        }

        return desc;
    }
}
